package com.gtlab1207.br_security.services;

import com.gtlab1207.br_security.models.dao.UserDao;
import com.gtlab1207.br_security.models.domain.AbacAttribute;
import com.gtlab1207.br_security.models.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 业务层
 */
@Service
public class UserService {

    @Autowired
    private UserDao userDao;

    /**
     * 根据用户名称查询用户信息
     * @param userName
     * @return
     */
    public User selectUser(String userName){
        User user = userDao.selectUser(userName);
        return user;
    }

    /**
     * 添加信息
     * @param user
     * @return
     */
    @Transactional
    public Integer insertUser(User user){
        Integer result = 0;
        if(user!=null){
            result = userDao.insertUser(user);
        }
        return result;
    }

    /**
     * 修改信息
     * @param user
     * @return
     */
    @Transactional
    public Integer updateUser(User user){
        Integer result = 0;
        if(user.getUserName()!=null){
            result = userDao.updateUser(user);
        }
        return result;
    }

    /**
     * 删除信息
     * @param userName
     * @return
     */
    @Transactional
    public Integer deleteUser(String userName){
        Integer result = 0;
        if(userName!=null && !"".equals(userName)){
            result = userDao.deleteUser(userName);
        }
        return result;
    }
}
